package com.kgd.news.controller.admin;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.ehcache.CacheKit;
import com.kgd.news.entity.SysSettings;
import com.kgd.news.utils.BaseController;

import java.util.List;

/**
 * @Email: huangsanm@foxmail.com
 * @Date: 2017/11/8
 * @Time: 上午10:46
 */
public class SettingsController extends BaseController {

    @Override
    public void list() {
        String sql = "select * from sys_settings where 1 = 1";
        /*String categoryid = getPara("categoryid");
        String title = getPara("title");
        if (!StringUtils.isEmpty(categoryid)) {
            sql += " and categoryid = " + categoryid;
        }
        if (!StringUtils.isEmpty(title)) {
            sql += " and title like '%" + title + "%'";
        }*/
        sql += " order by id desc";
        //Page<SysSettings> data = SysSettings.dao.paginate(getPageIndex(), PAGE_SIZE, "select *", sql);
        //setAttr("data", data);
        List<SysSettings> list = SysSettings.dao.find(sql);
        setAttr("data", list);
        render("settings_list.html");
    }




    @Override
    public void edit() {

    }

    @Override
    public void save() {
        String id = getPara("src_id");
        int val = getParaToInt("src_val");
        if(val == 1){
            val = 0;
        }else{
            val= 1;
        }
        Db.update("update sys_settings set value = "  + val + " where id = ?", id);
        CacheKit.remove("cache","setting");
        list();
    }

    @Override
    public void del() {

    }
}
